<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Strict//EN">
<HTML><HEAD><TITLE>Speed for the Apple //, and breaking the 20Mhz barrier</TITLE>
<META NAME="Creation_Date" CONTENT="06/24/19107">
<META NAME="Author" CONTENT="">
<META NAME="Generator" CONTENT=""></HEAD>
<BODY >
<FONT FACE="Arial">
Speed for the Apple //, and breaking the 20Mhz barrier<br>
by Richard Bennett<br>
Copyright (c) 1990 Apple Users' Group, Sydney<br>
Republished from Applecations, a publication of the Apple Users' Group, Sydney, Australia.<br>
<br>
<br>
 Yes, there is still some speed left in the old beast after all. The Apple // is on the verge of becoming a VERY fast machine. But first, I'd like to thank Cameron Brawn (and the AUG) for the documentation on the club's 4Mhz ZIP chip which runs the BBS, Darren Langer for the documentation on his RocketChip, and Cameron once again for the documentation on his TransWarp GS (before I bought mine). Unfortunately however, the club's ZIP chip died before I got a chance to have a good look at it.<br>
 Have you ever tried writing time critical code for the Apple //? In the old days it was easy, as every machine ran at roughly 1Mhz. These days, with so many different chip speeds, you have to be careful. Even Apple themselves have 5 different CPU speeds across the Apple // range (1 Mhz slow RAM in the ][+ //e and //GS, 1 Mhz fast RAM in the //GS, 2.8 Mhz slow RAM //GS, 2.8 Mhz fast RAM //GS, and 4 Mhz slow RAM //c+). If your timings aren't that critical, you can rule out the differences between fast RAM and slow RAM, and you've still got 3 different speeds. Now add this on to the three TransWarps for the //e (all different speeds), the ZIP chip //e (two top speeds), the Rocket chip //e (two top speeds), the TransWarp //GS (two top speeds), and the new ZIP chip //GS. This last chip is supposed to be shipping at the end of June 1990, but then again it's ZIP technology, so....<br>
 Lucky enough, all these chips can be slowed down to a more uniform speed (such as 1 Mhz). But unless you code routines to look for every one of them (they are all controlled differently!), you're still not going to get the same speed on every machine. Even then, the routine to actually slow the chip down would probably be longer than the entire routine you're trying to write!<br>
<br>
^The ZIP chip^<br>
 The ZIP chip is controlled via a bank of softswitches in the hardware page. The address lines on the chip are tested for these addresses, and acted upon as if they were part of the machine. The ZIP chip registers range from $C05A (normally set annunciator 1) to $C05F (clear annunciator 3 and double hires off, depending on IOUDIS being on of course). To talk to the ZIP, you first have to tell it that you actually want to talk to it. To do this, you write the value $5A to the ZIP lock/unlock switch. This will unlock the ZIP ready for your commands.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;#$5A&nbsp;&nbsp;&nbsp;&nbsp; ;Unlocking value<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C05A&nbsp;&nbsp;&nbsp;&nbsp;;Stick it 4 times<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C05A<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C05A<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C05A<br>
<br>
 To slow down to standard 1Mhz, simply write an invalid value to the lock/unlock register whilst it's unlocked. So, following the previous section of code, you could do this;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;#0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Invalid value<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C05A&nbsp;&nbsp;&nbsp;&nbsp;;Slow down to 1Mhz<br>
<br>
 This still leaves the ZIP unlocked, so your time dependent code should either lock the ZIP, or not go anywhere near the ZIP registers (or any code your routine calls, including ROM). To speed it back up again to it's original speed, make sure the ZIP is unlocked, and then do a write to location $C05B;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C05B&nbsp;&nbsp;&nbsp;&nbsp;;Speed up again<br>
<br>
 Of course you must now re-lock the ZIP again;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;#$A5&nbsp;&nbsp;&nbsp;&nbsp; ;This is the locking value<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C05A&nbsp;&nbsp;&nbsp;&nbsp;;Stick it in the lock/unlock register<br>
<br>
 Once the ZIP is locked, all accesses to it's registers are ignored, except for a sequence of four $5As written to the lock/unlock register. Changing the speed of the ZIP involves picking any of it's twenty speed settings, which range from 0.6667 to 4.0 megahertz (or to 8Mhz for the latest ZIP), and sticking the appropriate index value into the speed register at $C05D (whilst the ZIP is unlocked).<br>
<br>
^The RocketChip^<br>
 The RocketChip has a maximum speed of 5Mhz, which is not surprising considering the engineer behind it originally worked with ZIP technologies. It also has twenty speed settings, this time getting down to 50Khz as opposed to the ZIPs 500Khz. I am yet to see the technical manual on the RocketChip, so I can't really elaborate on how to program it. Suffice to say that the speed selection emulates the TransWarp protocols, which is one of the reasons why Applied Engineering had licensed technology from BPT (Bits and Pieces Technology Inc., who make the RocketChip) in it's new TransWarp II. Of course when BPT lost the court case with ZIP, Applied Engineering had to quickly re-design the TransWarp II into the TransWarp III, which brings us nicely to the TransWarp.<br>
<br>
^The TransWarp^<br>
 The TransWarp is configured by using dip switches on the card. The only hardware register in memory, is at $C074, and is purely a speed register. This location can contain three different values, which you can read or write at any time;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0 = Fastest speed (selected by switches on card, usually 3.6Mhz)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 = Normal 1Mhz<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3 = Disable the TransWarp completely until next cold-boot<br>
<br>
 Theoretically, by reading from $C074 and checking for a 0, 1 or 3, you could tell if a TransWarp is installed. The manual doesn't mention any way of recognising the card, so if any has a TransWarp that works (ie. mine doesn't work), please let us know. Sample code for testing for a TransWarp would then be something like this;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;$C074&nbsp;&nbsp;&nbsp;&nbsp;;Get speed register if possible<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CMP&nbsp;&nbsp;#2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Two is invalid<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BEQ&nbsp;&nbsp;NOTW<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;&nbsp;#3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Strip off all but bits 0 and 1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CMP&nbsp;&nbsp;$C074&nbsp;&nbsp;&nbsp;&nbsp;;Same as before?<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BNE&nbsp;&nbsp;NOTW<br>
YESTW&nbsp;&nbsp; EQU&nbsp;&nbsp;*<br>
<br>
NOTW&nbsp;&nbsp;&nbsp;&nbsp;EQU&nbsp;&nbsp;*<br>
<br>
 This method ensures that the location is read at least twice to verify the TransWarp's existence. If a TransWarp is not installed, this location should not only be garbage, but different garbage on each read. The likelihood of getting a value below $40 is pretty remote, let alone getting the same value twice below 4.<br>
<br>
 So, to slow down the TransWarp;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;$C074&nbsp;&nbsp;&nbsp;&nbsp;;Get current speed<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;SAVESP&nbsp;&nbsp; ;Save it<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;#1<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C074&nbsp;&nbsp;&nbsp;&nbsp;;Slow down to 1Mhz<br>
<br>
 And to speed it up again;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;SAVESP&nbsp;&nbsp; ;Retrieve the old speed<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C074&nbsp;&nbsp;&nbsp;&nbsp;;Set it again<br>
<br>
 At the time of writing this article, my attempts to get the documentation on the //c+ had failed. However, rumours of the //c+ containing either a ZIP chip or a ZIP chip hybrid abound. Considering this and Apple's association with Applied Engineering and the TransWarp GS, it would be safe to assume that the //c+ is controlled the same as either the ZIP chip, or the TransWarp (or RocketChip). Those of you requiring this information should contact Apple and see how you go. (Or if anyone has this information already, could you please let me know!)<br>
<br>
^GS specific^<br>
 For the //GS, there are two methods to slow the machine down. Apart from running your code in bank $E0 or $E1, the Apple engineers have put in a CPU slowdown switch, and a<br>
5.25&quot; slow down sensor. The slowdown switch is at $E0/C036, and in a normal system, is thus shadowed into bank 0 at $00/C036. Bit7 is the select bit.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;$C036&nbsp;&nbsp;&nbsp;&nbsp;;Get current setting<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;&nbsp;#$7F&nbsp;&nbsp;&nbsp;&nbsp; ;Make bit7 = 0 to slow down to 1Mhz<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C036&nbsp;&nbsp;&nbsp;&nbsp;;Stick it back in<br>
<br>
 Also, whenever the disk drive is activated, the machine is also slowed down. Although this isn't as simple as the above method, with a bit of fiddling you can arrive at the same solution. Considering the drives MUST run at 1Mhz, we can guarantee that activating the drive will slow down ALL CPU accelerators. Although they should all respect $E0/C036 as well, this method still works fine. How the ZIP GS handles slow downs I don't know, but this method simply must work with it!<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;$C02D&nbsp;&nbsp;&nbsp;&nbsp;;Get the current slot settings<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PHA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Save them<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EOR&nbsp;&nbsp;#$40&nbsp;&nbsp;&nbsp;&nbsp; ;Switch to the alternate setting<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; ie. If currently internal Disk Port, select the card<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;&nbsp;&nbsp;&nbsp;&nbsp; If currently card, select Disk Port<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; This will ensure that the drives do not get activated<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C02D&nbsp;&nbsp;&nbsp;&nbsp;;Set the new slot settings<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;$C0EE&nbsp;&nbsp;&nbsp;&nbsp;;Set read mode just in case<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;$C0E9&nbsp;&nbsp;&nbsp;&nbsp;;Drive on, //GS is now running at 1Mhz<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PLA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Restore original settings<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C02D&nbsp;&nbsp;&nbsp;&nbsp;;Set them back again<br>
<br>
 Of course to restore it again;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;$C02D&nbsp;&nbsp;&nbsp;&nbsp;;Get it<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PHA&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Save it<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EOR&nbsp;&nbsp;#$40&nbsp;&nbsp;&nbsp;&nbsp; ;Flip it<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C02D&nbsp;&nbsp;&nbsp;&nbsp;;Set the new<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;$C0E8&nbsp;&nbsp;&nbsp;&nbsp;;Turn drive off (fake drive that is)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PLA<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;$C02D&nbsp;&nbsp;&nbsp;&nbsp;;Restore the setting<br>
<br>
 Of course with System 5 and it's 14 slot architecture, this means that you would either have to disable interrupts, or not use this technique under GS/OS. Either way, the $C036 is of course preferable. (And if Matt deatherage finds out, don't dare tell him that I suggested it!)<br>
<br>
^TransWarp GS^<br>
 The TransWarp GS will respect the //GS speed register and slow down to 1Mhz whenever the system requires it, and of course speeding up again once the speed register is restored to high speed. This means that most programs can simply slow<br>
down the //GS via $E0/C036, perform their time critical code, and then restore $E0/C036 again. TransWarp GS also has an IRQ slow down feature, which can come in handy. As an option, you can tell TransWarp GS to slow down to the current //GS speed whenever the interrupt bit in the status register is set. This effectively turns the TransWarp GS off, and enables the $E0/C036 switch to toggle between 2.8Mhz and 1Mhz. So all you need to do is this;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SEI<br>
<br>
 Simple huh? However, considering it's only an option, you first have to check that it's activated. To do this, you either have to turn on AppleTalk/IRQ in the TransWarp GS desk accessory, or call the EnableIRQLogic routine in the TransWarp GS ROM;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JSL&nbsp;&nbsp;$BC/FF38 ;EnableIRQLogic call<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SEI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;SEI now works fine.<br>
<br>
 But to speed it up again, you should restore the original setting of the IRQLogic. So, starting with the slow down routine;<br>
<br>
GOSLOW&nbsp;&nbsp;JSL&nbsp;&nbsp;$BC/FF3C ;GetTWConfig - Returns current config in A<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; (Only four bits are actually used)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STA&nbsp;&nbsp;TWCONFIG ;Save the current config<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JSL&nbsp;&nbsp;$BC/FF38 ;EnableIRQLogic<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SEI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Slow me down!<br>
<br>
 And the restore;<br>
<br>
GOFAST&nbsp;&nbsp;CLI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Speed me up!<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;TWCONFIG ;Restore the original config settings<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JSL&nbsp;&nbsp;$BC/FF40 ;SetTWConfig<br>
<br>
^Code Timing^<br>
 So how does this all affect your time critical code?<br>
 For starters, actually slowing down the chip can be a real pain. Recognising all the different accelerators can be a long winded process. What we should be able to do instead, is read the speed of all the chips at once, and use that value to generate extra delays in the code. Unfortunately, this requires recognising each of the accelerators as well, so we may as well rule out the chip as part of a solution. Luckily enough, there are other parts of the hardware that generate a constant timer value across all of the machines, and a few extra ones in the //GS.<br>
 For the ][+ and //e we can use the vertical blanking period as a timer. In the //c, and a //e with a mouse card, we could use, once again, the vertical blanking period, or a vertical blanking interrupt. In the //GS, we can use any of the following; the 1 second interrupt, the .25 second<br>
interrupt, the vertical blanking period, the heartbeat queue (driven from VBL interrupts), the tick counter (driven from the VBL interrupts), and scan-line interrupts.<br>
<br>
^VBLs - Vertical Blanks^<br>
 The vertical blanking period is the time it takes the electron gun, inside the monitor, to get from the bottom right corner of the screen, to the top left corner of the screen. During this time, the screen display is not updated. This is perfect for re-drawing graphics in memory before the gun starts to re-trace the screen. Using this method, you have approximately 10819-10835 instruction cycles running at 1 Mhz on a 60 Hz screen, which occurs 60 times each second. As you can see, we now have a logical way of timing our code, independent of the actual speed of the CPU.<br>
 Bit 7 of location $C019 indicates whether the vertical blanking (VBL) period is currently active or not. This is where we start to have problems. On the pre-//GS machines, a one in bit 7 meant that a VBL was occurring, but on the //GS it's a zero. This means that if we require the current state of the electron gun, we have to code something like this;<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SEC<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JSR&nbsp;&nbsp;$FE1F&nbsp;&nbsp;&nbsp;&nbsp;;Call standard //GS ID routine<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ROR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Drag the carry into the accumulator, bit 7<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EOR&nbsp;&nbsp;$C019&nbsp;&nbsp;&nbsp;&nbsp;;Test bit 7 of the VBL indicator<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BPL&nbsp;&nbsp;:VBLACT&nbsp;&nbsp;;Yep, VBL is occurring<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BMI&nbsp;&nbsp;:NOVBL&nbsp;&nbsp; ;Nup, must be re-tracing<br>
<br>
 However, if all we need is a timed delay for as close to one second as we can get, the following code will suffice.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDX&nbsp;&nbsp;#60&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;60 VBLs for 60 Hz (plus or minus up to one re-trace)<br>
VBLOOP&nbsp;&nbsp;LDA&nbsp;&nbsp;$C019&nbsp;&nbsp;&nbsp;&nbsp;;Wots the gun doing?<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BPL&nbsp;&nbsp;*-3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;Wait for it to go high<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;$C019&nbsp;&nbsp;&nbsp;&nbsp;;Must be high now!<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BMI&nbsp;&nbsp;*-3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;Wait for it to go low again<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DEX&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Done yet?<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BNE&nbsp;&nbsp;VBLOOP<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;$C019&nbsp;&nbsp;&nbsp;&nbsp;;Wait one more for non-alignment<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BPL&nbsp;&nbsp;*-3<br>
<br>
 This routine will delay for one second, and considering that the position of the gun can't be read on pre-//GS machines, an extra poll is performed in case we started just before it went high (and wasted the first BPL). This of course is optional, and shouldn't be required unless you need AT LEAST one second of delay.<br>
<br>
^Waiting around at $FCA8^<br>
 The WAIT routine in the //GS at $FF/FCA8 (shadowed into $00/FCA8), automatically slows the machine down to 1Mhz by<br>
changing the speed register at $C036. Once the delay period has ended, it restores the original value. Of course the TransWarp GS will respect this and slow down as well. However, more elaborate routines will require more control of timing than the overheads and limitations of the WAIT routine.<br>
 To use WAIT under GS/OS, you would either have to use a _FWEntry call, which incurs the overhead of the Toolbox, or setup a WAIT call routine in bank 0 to set up the appropriate environment before and after the call. For games which use the joystick, it is quite easy to set up and call a routine in bank 0 which calls the monitor paddle routines directly, so why not a WAIT routine as well?<br>
<br>
^Interrupts^<br>
 Interrupts can be very handy. Here is a simple 1 second interrupt handler under P8. You can type it in at $300 if you wish;<br>
<br>
START&nbsp;&nbsp; CLC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Switch to native 65c816<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XCE<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;REP&nbsp;&nbsp;$20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;Use long m<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;#TIC<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STAL $E10055&nbsp;&nbsp;;Point the 1 second IRQ vector<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SEP&nbsp;&nbsp;$20&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; to point to me<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;#^TIC<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STAL $E10057<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;#4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Turn on 1 second interrupts<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TSB&nbsp;&nbsp;$C023<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SEC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Switch back and exit<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XCE<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RTS<br>
TIC&nbsp;&nbsp;&nbsp;&nbsp; PHB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Tick entry. Save data bank<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PHK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Get my bank<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PLB<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;$C030&nbsp;&nbsp;&nbsp;&nbsp;;Make a little tick noise<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDX&nbsp;&nbsp;#10<br>
LOOP&nbsp;&nbsp;&nbsp;&nbsp;PHA<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PLA<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DEX<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BPL&nbsp;&nbsp;LOOP<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;$C030<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LDA&nbsp;&nbsp;#$40&nbsp;&nbsp;&nbsp;&nbsp; ;Reset 1 second interrupt<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TSB&nbsp;&nbsp;$C032<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PLB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Restore the data bank<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CLC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Tell ROM that I handled it<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RTL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ;Exit<br>
<br>
 The ROM (and Toolbox) interrupt hooks all roughly work the same way as the above routine. It is usually up to the caller to clear the interrupt, and signal to the ROM if it was handled correctly. The Toolbox routines _IntSource and _SetVector should really be used for interrupt handling.<br>
However, if you need speed, you'll have to access the switches directly, as I did in the above example.<br>
<br>
^Apple Offerings^<br>
 The latest in speed from Apple, is the new High Speed SCSI card. And because it was on the Apple // first, it's safe to say that all new Macs now use the Apple // SCSI technology. Whilst not a CPU accelerator card, it does accelerate access to SCSI devices. Whilst the old SCSI card was able to use pseudo-DMA, which still uses the CPU for the final transfer of the data, the new card has real DMA. The following figures are for loading 102 x 32k super hires pictures with the FAST! option of my Slide Master program (as demonstrated at the May Apple // meeting). All tests were run with GS/OS RAM cache turned off:<br>
<br>
From /RAM5 took 43 seconds<br>
From the new SCSI card took 22 seconds (who needs a TransWarp GS?)<br>
From the new SCSI card with 7Mhz TransWarp GS took 16 seconds<br>
<br>
^What the future holds^<br>
 As of finishing this article (31st May 1990), there were various rumours floating around about even faster CPUs. ZIP technology and a rating of 20Mhz has been mentioned, as has a 20Mhz TransWarp III. Also, the 21Mhz reverse engineered 65C816 should be released some time in the next couple of months, however a card to handle it may be a bit longer.<br>
 If you're interested in speeding up your Apple //, then there are quite a few choices already. With the seemingly impossible 20Mhz barrier apparently about to be broken on the //GS and //e, we can look forward to some pretty powerful machines. For the latest on speed, try coming along to the //GS SIG, or logging on to AUGABBS. We usually mention, amongst many other things, the latest developments in accelerator technology.<br>
</FONT>
<hr><p><small><font face="arial">THIS CONTENT COPYRIGHT &copy; 2007, <a href="http://homepage.mac.com/sydamug">APPLE MACINTOSH USERS' GROUP, SYDNEY</a></font></small><BR><small><font face="arial">Permission has been obtained to make this material available on the Internet.</font></small></p><p><small><font face="arial">Permission is hereby granted for non-profit user groups to republish this content.</font></small><BR><small><font face="arial">PLEASE CREDIT THE AUTHOR AND THE SOURCE: Applecations, publication of the Apple Users' Group, Sydney, Australia</font></small></p><p><small><font face="arial">THIS PAGE COPYRIGHT &copy; 2007, <a href="../../index.htm">ANDREW ROUGHAN</a></font></small></p><!-- Site Meter --><script type="text/javascript" src="http://s37.sitemeter.com/js/counter.js?site=s37ajraug"></script><noscript><a href="http://s37.sitemeter.com/stats.asp?site=s37ajraug" target="_top"><img src="http://s37.sitemeter.com/meter.asp?site=s37ajraug" alt="Site Meter" border="0"/></a></noscript><!-- Copyright (c)2006 Site Meter --></BODY></HTML>